import numeral from 'numeral';
import { downColor, flatColor, upColor } from '../constants/color';

export const getColor = (target: string | number, prevClose: string | number) => {
  if (+target > +prevClose) {
    return `text-[${upColor}]`;
  } else if (+target < +prevClose) {
    return `text-[${downColor}]`;
  } else {
    return `text-[${flatColor}]`;
  }
};

export const getStyleColor = (target: string | number, prevClose: string | number) => {
  if (+target > +prevClose) {
    return upColor;
  } else if (+target < +prevClose) {
    return downColor;
  } else {
    return flatColor;
  }
};

export const formatChineseAmount = (amount: string | number): string => {
  if (amount === '-') {
    return amount;
  }

  if (+amount >= 10000 && +amount < 100000000) {
    return `${numeral(+amount / 10000).format('0.00')}万`;
  } else if (+amount >= 100000000) {
    return `${numeral(+amount / 100000000).format('0.00')}亿`;
  } else {
    return numeral(+amount).format('0.00');
  }
};
